//
//  MusicDetailHeaderView.m
//  OurRelaxDemo
//
//  Created by 王雅蓉 on 15/6/24.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "MusicDetailHeaderView.h"

#import <UIImageView+WebCache.h>

@interface MusicDetailHeaderView ()
{
    UIImageView *userIV;
}

@property (nonatomic, retain) UILabel *titleL;
@property (nonatomic, retain) UILabel *descL;

@end

@implementation MusicDetailHeaderView

-(void)dealloc
{
    [_musicDetailForHV release];
    [_titleL release];
    [_descL release];
    
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self createSubviews];
        //NSLog(@"22222");
        self.musicDetailForHV = [[MusicDetailModel alloc] init];
        
    }
    return self;
}

-(void)createSubviews
{
    self.contentSize = CGSizeMake(self.frame.size.width * 3, self.frame.size.height);
    
    
    self.leftIV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    self.leftIV.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.leftIV];
    [self.leftIV release];
    
    self.centerIV = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width, 0, self.frame.size.width, self.frame.size.height)];
    self.centerIV.backgroundColor = [UIColor cyanColor];
    [self addSubview:self.centerIV];
    [self.centerIV release];
    
    self.rightIV = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 2, 0, self.frame.size.width, self.frame.size.height)];
    self.rightIV.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:self.rightIV];
    [self.rightIV release];
    
    UIView *centerView = [[UIView alloc] initWithFrame:self.leftIV.frame];
    centerView.backgroundColor = [UIColor whiteColor];
    centerView.alpha = 0.6;
    [self.centerIV addSubview:centerView];
    //[self.rightIV addSubview:centerView];
    [centerView release];
    
    UIView *rightView = [[UIView alloc] initWithFrame:self.leftIV.frame];
    rightView.backgroundColor = [UIColor whiteColor];
    rightView.alpha = 0.6;
    //[self.centerIV addSubview:centerView];
    [self.rightIV addSubview:rightView];
    [rightView release];
    
    userIV = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 2.0 - 40, 30, 80, 80)];
    userIV.backgroundColor = [UIColor whiteColor];
    userIV.image = [UIImage imageNamed:@"aboutUs.jpg"];
    userIV.layer.masksToBounds = YES;
    userIV.layer.cornerRadius = 35;
    [self.centerIV addSubview:userIV];
    [userIV release];
    
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(userIV.frame.origin.x - 8, 100, 120, 80)];
    _titleL.text = @"保持微笑(*^__^*)";
    _titleL.font = [UIFont systemFontOfSize:14.0];
    _titleL.textColor = [UIColor darkGrayColor];
    [self.centerIV addSubview:_titleL];
    [_titleL release];
    
    self.descL = [[UILabel alloc] initWithFrame:CGRectMake(30, 20, self.rightIV.frame.size.width - 60, 140)];
    _descL.font = [UIFont systemFontOfSize:14.0];
    _descL.textColor = [UIColor darkGrayColor];
    _descL.numberOfLines = 0;
    [self.rightIV addSubview:_descL];
    [_descL release];

}

-(void)setMusicDetailForHV:(MusicDetailModel *)musicDetailForHV
{
    if (_musicDetailForHV != musicDetailForHV) {
        
        [_musicDetailForHV release];
        _musicDetailForHV = [musicDetailForHV retain];
        
    }
    //NSLog(@"sdddfggtg %@",musicDetailForHV.pics);
    NSString *picStr = [((NSMutableArray *)musicDetailForHV.pics) firstObject];
    NSString *urlStr = [picStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlStr];
    [self.leftIV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"headerViewCache.jpeg"]];
    [self.centerIV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"headerViewCache.jpeg"]];
    [self.rightIV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"headerViewCache.jpeg"]];
    
    _descL.text = musicDetailForHV.tweet;

}

@end
